package com.ftg.learn.bus.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.learn.bus.VO.*;
import com.ftg.learn.bus.entity.BusExpenditure;
import com.ftg.learn.bus.entity.request.InsertJFZCRequest;
import com.ftg.learn.bus.service.IBusExpenditureService;
import com.ftg.learn.util.ResEntity;
import com.ftg.learn.util.ResPageEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 公车经费支出登记表 前端控制器
 * </p>
 *
 * @author lalala
 * @since 2022-03-07
 */
@Log4j
@RestController
@RequestMapping("/bus/bus-expenditure")
@Api(tags = "公车经费支出登记管理功能列表")
public class BusExpenditureController extends CrudpController<BusExpenditure, IBusExpenditureService> {

    @PostMapping("/insertEx")
    @ApiOperation(value = "添加公车经费支出登记(真实使用的添加)")
    ResEntity insertOne(@RequestBody InsertJFZCRequest insertAutoRequest) {
        return super.service.insertInfo(insertAutoRequest) ? new ResEntity().OK() : new ResEntity().Failure();
    }


    /**
     * 修改经费支出表，以及删除经费表并重新添加，达到修改经费表的目的。
     * @param insertAutoRequest insertAutoRequest
     * @return
     */
    @PutMapping("/updateEx01")
    ResEntity updateEx(@RequestBody busExUpdateVo insertAutoRequest){
        return super.service.updateExFund1(insertAutoRequest) ? new ResEntity().OK() : new ResEntity().Failure();
    }


    /**
     * 修改经费支出表，以及删除经费表并重新添加，达到修改经费表的目的。
     * @param busExFundsVo busExFundsVo
     * @return
     */
    @PutMapping("/updateEx")
    ResEntity updateEx(@RequestBody busExFundsVo busExFundsVo){
        return super.service.updateExFund(busExFundsVo) ? new ResEntity().OK() : new ResEntity().Failure();
    }

    /**
     * 分页查询经费支出表全部数据加上对应beid的经费表经费支出总和。
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/showBusExAndSumCost")
    ResPageEntity showBusExAndSumCost(@RequestParam int page, @RequestParam int limit){
//        Page<busExCostAmountVo> p = new Page<>(page,limit);
//        p.setRecords(super.service.showBusExAndSumCost(p));

        IPage<busExCostAmountVo> ip =new Page<>(page,limit);
        ip.setRecords(super.service.showBusExAndSumCost(ip));


        return new ResPageEntity(ip);
    }

    /**
     * 按负责人姓名模糊查找页查询经费支出表全部数据加上对应beid的经费表经费支出总和。
     */
    @GetMapping("/showBusExAndSumCostByDname")
    ResPageEntity showBusExAndSumCostByDname(@RequestParam String dname,@RequestParam int page, @RequestParam int limit){
        IPage<busExCostAmountVo> ip =new Page<>(page,limit);
        ip.setRecords(super.service.showBusExAndSumCostByDname(ip,dname));
        return new ResPageEntity(ip);
    }

    /**
     * 根据此经费支出表id查询此次支出表详情
     * @param beid
     * @return
     */
    @GetMapping("/showFund")
    ResEntity showFund(@RequestParam Long beid){
        return new ResEntity().OK(super.service.showFund(beid));
    }

    /**
     * 列出参数表中所有的经费类型
     * @return
     */
    @GetMapping("/showCostType")
    ResEntity showCostType(){
        return new ResEntity().OK(super.service.showCostType());
    }


    /**
     * 列出参数表中所有的厂商
     * @return
     */
    @GetMapping("/showManufacturer")
    ResEntity showManufacturer(){
        return new ResEntity().OK(super.service.showManufacturer());
    }

    /**
     * 删除经费支出表数据，同时删除支出表内和审批表内关联数据
     * @param beid
     * @return
     */
    @DeleteMapping("/delBusExAndFundApproval/{beid}")
    ResEntity delBusExAndFundApproval(@PathVariable("beid") Long beid){
        return super.service.delBusEx(beid) ? new ResEntity().OK() : new ResEntity().Failure();
    }


    /**
     * 在审批表内查询经费支出表全部数据加上对应beid的经费表经费支出总和。
     */
    @GetMapping("showBusExAndSumCostInApp/{beid}")
    ResEntity showBusExAndSumCostInApp(@PathVariable("beid") Long beid){
        return new ResEntity().OK(super.service.showBusExAndSumCostInApp(beid));
    }

}
